<template>
  <div>
    <!-- 睿蓝厂端打款审核 -->
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
    >
    </FilterTable>

    <BaseDialog
      :visible.sync="issearch"
      :title="'服务站查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher  @close="dealercloseHandler" />
    </BaseDialog>

     <Drawer
      :visible.sync="auditMark"
      :title="'打款审核'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <paymentAudit :row="auditRow" @close="auditCloseHandler" />
    </Drawer>

    <!-- 查看凭证 -->
    <el-image-viewer :url-list="imageList" v-show="imagesViewShow" :on-close="closeImagesViewer"></el-image-viewer>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { oemRemitInfo} from '@/api/partsmanage/financialManagement/capitalAccount/index';
import ownerSeacher from '@/pages/partsmanage/claim/approve/ownerSeacher';
import paymentAudit from '@/pages/partsmanage/financialManagement/oemPaymentReview/customPopup/paymentAudit';
import { notifyAction } from '@/utils';
import ElImageViewer from 'element-ui/packages/image/src/image-viewer';
import { findFileByUrl } from '@/api/partsmanage/financialManagement/capitalAccount/index';

export default {
  name: "oemPaymentReview",
  mixins: [dictionary],
  components: {ownerSeacher,paymentAudit,ElImageViewer},
  data() {
    return{
      issearch:false,
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchApi: oemRemitInfo,
      fetchParams: {xhrAbort: true},
      auditMark:false,
      auditRow:{},
      imageList:[],
      imagesViewShow:false,
    };
  },
  methods: {
    closeImagesViewer() {
      this.imagesViewShow = false;
    },
    async look(row){//查看按钮
      if(row.uploadFile.length <= 0 || row.uploadFile[0].url == null || row.uploadFile[0].url == ''){
        return notifyAction('当前记录凭证为空!', 'warning');
      }

      this.imagesViewShow = true;
      this.imageList = [];
      findFileByUrl(row.uploadFile[0].url).then(res => {
        this.imageList.push(res.data);
      })
    },
    audit(row){
      this.auditMark = true;
      this.auditRow = row;
    },
    auditCloseHandler(val){
      this.auditMark = false;
      //刷新页面
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    seacherFun(){
      this.issearch = true
    },
    dealercloseHandler(val){
      if(val){
        this.topFilterList.find(x=>x.fieldName=='dealerCode').initialValue=val.dealerCode;
      }
      this.issearch=false;
    },
    createTopFilterList() {
      return[
        {
          type: 'INPUT',
          label: '服务站查询',
          fieldName: 'dealerCode',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          }
        },
        {
          type: 'RANGE_DATE',
          label: '打款日期',
          fieldName: 'remitDate1|remitDate2',
          placeholder: '请选择...',
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'RANGE_DATE',
          label: '提交日期',
          fieldName: 'updateDate1|updateDate2',
          placeholder: '请选择...',
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'RANGE_DATE',
          label: '审核日期',
          fieldName: 'auditDate1|auditDate2',
          placeholder: '请选择...',
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'INPUT', 
          label: '票号', 
          fieldName: 'paymentNo',
        },
        {
          type: 'SELECT', 
          label: '状态', 
          fieldName: 'paymentStatus', 
          placeholder: '请选择',
          itemList: this.createDictList('3008',[30081001,30081005])
        },
      ]
    },
    createTableColumns () {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          align:"center",
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          align:"center",
          render: (props, h) => {
            return (
              <div>
                <el-button disabled = {props.row.paymentStatus != 30081002} size="mini" type="text" onClick={() => this.audit(props.row)}>
                  审核
                </el-button>
                <el-button size="mini" type="text" onClick={() => this.look(props.row)}>
                  查看凭证
                </el-button>
              </div>
            );
          }
        },
        {
          title: '状态',
          dataIndex: 'paymentStatus',
          sorter: true,
          filter: true,
          dictItems: this.createDictList('3008')
        },
        {
          title: '服务站代码',
          dataIndex: 'companyCode',
          sorter: true,
          align:"center"
        },
        {
          title: '服务站名称',
          dataIndex: 'dealerName',
          sorter: true,
          align:"center"
        },
        {
          title: '票号',
          dataIndex: 'paymentNo',
          sorter: true,
          align:"center"
        },
        {
          title: '款项类型',
          dataIndex: 'paymentType',
          sorter: true,
          filter: true,
          dictItems: this.createDictList('3007')
        },
        {
          title: '打款方式',
          dataIndex: 'paymentWay',
          sorter: true,
          filter: true,
          dictItems: this.createDictList('3009')
        },
        {
          title: '收款银行',
          dataIndex: 'bank',
          sorter: true,
          align:"center"
        },
        {
          title: '打款金额',
          dataIndex: 'amount',
          sorter: true,
          precision: 2,
          align:"center"
        },
        {
          title: '打款日期',
          dataIndex: 'remitDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat:'yyyy-MM-dd'
        },
        {
          title: '打款人',
          dataIndex: 'paymentPerson',
          sorter: true,
          align:"center"
        },
        {
          title: '摘要',
          dataIndex: 'content',
          sorter: true,
          align:"center"
        },
        {
          title: '提交日期',
          dataIndex: 'updatedAt',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat:'yyyy-MM-dd'
        },
        {
          title: '提交人',
          dataIndex: 'createdName',
          sorter: true,
          align:"center"
        },
        {
          title: '审核日期',
          dataIndex: 'auditDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat:'yyyy-MM-dd'
        },
        {
          title: '审核人',
          dataIndex: 'auditName',
          sorter: true,
          align:"center"
        },
        {
          title: '审核意见',
          dataIndex: 'auditView',
          sorter: true,
          align:"center"
        }
      ]
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
  }
}
</script>